package pratice.learn.flow;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.junit.Test;

import java.util.List;

/**
 * 学习查询历史的流程实例、流程变量、任务等
 * @author 吴宇亮 on 2019/5/16 0016 上午 11:47
 */
public class ProcessHistory {

    public static ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault().buildProcessEngine();

    /**
     * 1.查询历史流程实例
     */
    @Test
    public void listProcessInstantHistory(){
        List<HistoricProcessInstance> list = processEngine.getHistoryService()
                .createHistoricProcessInstanceQuery()
                .list();
        for (HistoricProcessInstance historicProcessInstance : list) {
            System.out.println(historicProcessInstance.getStartTime());
        }
    }

    /**
     * 2.查询历史活动节点
     */
    @Test
    public void listActivitiHistory(){
        List<HistoricActivityInstance> list = processEngine.getHistoryService()
                .createHistoricActivityInstanceQuery()
                .list();
        for (HistoricActivityInstance historicActivityInstance : list) {
            System.out.println(historicActivityInstance.getActivityName());
        }
    }

    /**
     * 3.查询历史任务
     */
    @Test
    public void listTaskHistory(){
        List<HistoricTaskInstance> list = processEngine.getHistoryService()
                .createHistoricTaskInstanceQuery()
                .list();
        for (HistoricTaskInstance historicTaskInstance : list) {
            System.out.println(historicTaskInstance.getName());
        }
    }

    /**
     * 4.查询历史流程变量
     */
    @Test
    public void listVariableHistory(){
        List<HistoricVariableInstance> list = processEngine.getHistoryService()
                .createHistoricVariableInstanceQuery()
                //注意模糊查询要自己加%
                .variableNameLike("%请假%")
                .list();
        for (HistoricVariableInstance vo : list) {
            System.out.println(vo.getVariableTypeName() + ":" + vo.getVariableName());
        }
    }





}
